Skip to content

Add support for creating self-decrypting binaries #2315

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

will-v-pi
Copy link
Contributor

@will-v-pi will-v-pi commented Feb 24, 2025

This adds extra functionality to the pico_encrypt_binary function to allow creating self-decrypting binaries, including specifying the OTP page to use for the AES key.

pico_encrypt_binary(hello_encrypted
    ${CMAKE_CURRENT_LIST_DIR}/privateaes.bin
    ${CMAKE_CURRENT_LIST_DIR}/ivsalt.bin
    EMBED
    OTP_KEY_PAGE 29)

The main non-backwards-compatible change is the addition of a new IV salt bin file which is required and must be passed as the second argument. This will break any uses of pico_encrypt_binary, and has been added for security purposes, as we now salt the public IV with a salt stored in OTP.

The other non-backwards-compatible change it that if you previously called:

pico_encrypt_binary(my_target my_aesfile.bin my_sigfile.pem)

you now need to call

pico_encrypt_binary(my_target my_aesfile.bin my_iv_salt.bin SIGFILE my_sigfile.pem)

due to the new argument parsing. I think that this is fine, because the only time you'd pass a separated SIGFILE to pico_encrypt_binary is when you're using a different signing key for the binary vs the encrypted blob, which is not a common use case.

This PR requires use of the picotool encrypted-shares branch (raspberrypi/picotool#207), so should be merged after that.

will-v-pi added a commit to raspberrypi/picotool that referenced this pull request Apr 28, 2025
@will-v-pi will-v-pi force-pushed the self-decrypting-only branch from c0f179f to fdc61ca Compare May 19, 2025 09:30
# This sets the target properties PICOTOOL_AESFILE to AESFILE, PICOTOOL_IVFILE to IVFILE, and
# PICOTOOL_ENC_SIGFILE to SIGFILE if specified, else PICOTOOL_SIGFILE.
#
# Optionally, use EMBED to embed a decryption stage into the encrypted binary.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another stupid question: when/why would you not want to embed a decryption stage into the encrypted binary?

# and takes up more code size.
# This sets the target property PICOTOOL_USE_MBEDTLS_DECRYPTION to TRUE.
#
# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this have some default or implicit value, if not explicitly set?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this same OTP page (or some fixed offset from it) also used for storing the IV salt, or might it make sense to have an OTP_SALT_PAGE parameter?

The embedded decryption stage only works if the binary is written to Flash and then loaded to SRAM by the bootrom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants